package com.codeerror.demo.util;

import com.codeerror.demo.bean.AnniversaryBean;
import com.codeerror.demo.bean.CountDownBean;
import com.codeerror.demo.bean.PromiseBean;
import com.codeerror.demo.bean.TodoBean;
import com.codeerror.demo.bean.TodoListBean;
import com.codeerror.demo.bean.WordsBean;

import org.litepal.LitePal;

import java.util.List;

/**
 * 查找数据库
 */
public class FindDataUtil {

    /**
     * 获取指定日期的全部待办
     */
    public static List<TodoBean> getTodoData(long time) {
        return LitePal.where("time = ?", String.valueOf(time)).find(TodoBean.class);
    }

    /**
     * 获取指定日期的全部待办集
     */
    public static List<TodoListBean> getTodoListData(long time) {
        return LitePal.where("formattedTime = ?",
                DateUtil.getFormattedTime(time)).find(TodoListBean.class);
    }

    /**
     * 获取全部倒计时卡片
     */
    public static List<CountDownBean> getCountDownData(long curTime) {
        return LitePal.where("time > ?",
                String.valueOf(curTime)).find(CountDownBean.class);
    }

    /**
     * 获取全部承诺卡片
     */
    public static List<PromiseBean> getPromiseData() {
        return LitePal.where("isAchieved = ?", "0").find(PromiseBean.class);
    }

    /**
     * 获取全部纪念日卡片
     */
    public static List<AnniversaryBean> getAnniversaryData() {
        return LitePal.findAll(AnniversaryBean.class);
    }

    /**
     * 获取指定日期的全部“每日一句”内容
     */
    public static List<WordsBean> getWordsData(long time) {
        return LitePal.where("formattedTime = ?",
                DateUtil.getFormattedTime(time)).find(WordsBean.class);
    }
}
